package com.example.project3;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class InterestSelectActivity extends AppCompatActivity {

    private Button btnBack, btnConfirm;
    private CheckBox cbRead, cbPhoto, cbTennis;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.interest_select_activity);

        btnBack = findViewById(R.id.btn_back_interest);
        btnConfirm = findViewById(R.id.btn_confirm);
        cbRead = findViewById(R.id.cb_read);
        cbPhoto = findViewById(R.id.cb_photo);
        cbTennis = findViewById(R.id.cb_tennis);

        // 返回按钮（点击颜色变深为系统默认反馈）
        btnBack.setOnClickListener(v -> finish());

        // 确定按钮：回传选中的兴趣
        btnConfirm.setOnClickListener(v -> {
            StringBuilder interest = new StringBuilder();
            if (cbRead.isChecked()) interest.append("阅读、");
            if (cbPhoto.isChecked()) interest.append("摄影、");
            if (cbTennis.isChecked()) interest.append("乒乓球、");

            // 去掉最后一个“、”
            if (interest.length() > 0) {
                interest.deleteCharAt(interest.length() - 1);
            }

            Intent intent = new Intent();
            intent.putExtra("interest", interest.toString());
            setResult(RESULT_OK, intent);
            finish(); // 关闭当前页
        });
    }
}